diff --git a/docs/docs/enviroment.md b/docs/docs/enviroment.md index 54e6b31..893e3fc 100644 --- a/docs/docs/enviroment.md +++ b/docs/docs/enviroment.md @@ -119,6 +119,7 @@ Példa: `kábel.halgass` |Név|Leírás|Használat|Példa| |---|---|---|---| |halgass|Hallgat egy porton.|`halgass(host: string, port: number): halgató`|`halgass(szaft"0.0.0.0"szaft,1010)`| +|kapcsolódj|Rákapcsolódik egy célra.|`kapcsolódj(target: string): kapcsolat`|`kapcsolódj(szaft"example.com:80"szaft)`| :::warning diff --git a/docs/versioned_docs/version-1.0.0/enviroment.md b/docs/versioned_docs/version-1.0.0/enviroment.md index 54e6b31..893e3fc 100644 --- a/docs/versioned_docs/version-1.0.0/enviroment.md +++ b/docs/versioned_docs/version-1.0.0/enviroment.md @@ -119,6 +119,7 @@ Példa: `kábel.halgass` |Név|Leírás|Használat|Példa| |---|---|---|---| |halgass|Hallgat egy porton.|`halgass(host: string, port: number): halgató`|`halgass(szaft"0.0.0.0"szaft,1010)`| +|kapcsolódj|Rákapcsolódik egy célra.|`kapcsolódj(target: string): kapcsolat`|`kapcsolódj(szaft"example.com:80"szaft)`| :::warning diff --git a/extension/astrolang-extension-1.0.2.vsix b/extension/astrolang-extension-1.0.2.vsix new file mode 100644 index 0000000..0651d87 Binary files /dev/null and b/extension/astrolang-extension-1.0.2.vsix differ diff --git a/extension/index.js b/extension/index.js index e9adb88..c07fe37 100644 --- a/extension/index.js +++ b/extension/index.js @@ -66,6 +66,7 @@ vscode.languages.registerCompletionItemProvider('astrolang', { "vége", "halgass", + "kapcsolódj", "kérés", "írj", "olvass", diff --git a/extension/package.json b/extension/package.json index a6cb29a..36ff78e 100644 --- a/extension/package.json +++ b/extension/package.json @@ -2,7 +2,7 @@ "name": "astrolang-extension", "displayName": "Astro Lang", "icon": "asl.png", - "version": "1.0.1", + "version": "1.0.2", "description": "The extension for Astro Lang", "license": "MIT", "author": "Afonya", diff --git a/src/enviroment.rs b/src/enviroment.rs index 40cfb12..4a99d64 100644 --- a/src/enviroment.rs +++ b/src/enviroment.rs @@ -436,12 +436,12 @@ fn kabel_irj(machine: &mut Machine, op: &DecompiledOperation, args: Vec s.value.clone(), _ => String::new() }; - match listener.write_all(write.as_bytes()) { + match stream.write_all(write.as_bytes()) { Ok(_) => {}, Err(e) => { error(format!("Failed to write to stream: {}", e), machine, op); @@ -540,6 +540,40 @@ fn kabel_keres(machine: &mut Machine, op: &DecompiledOperation, args: Vec) -> VMMemory { + arg_expect(&args, 0, "string", machine, op); + let str = match &args[0] { + VMMemory::String(s) => s.value.clone(), + _ => String::new() + }; + let stream = match TcpStream::connect(&str) { + Ok(s) => s, + Err(err) => { + error(format!("Failed to connect to {}: {}", str, err), machine, op); + return VMMemory::Null(VMMemoryNull { variable_id: 0 }); + } + }; + machine.storage.push(Box::new(stream)); + let ret_table: Vec = vec![ + TableValue { + key: VMMemory::String(VMMemoryString { value: String::from("olvass"), variable_id: 0 }), + value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: kabel_olvass, variable_id: 0 }), + }, + TableValue { + key: VMMemory::String(VMMemoryString { value: String::from("írj"), variable_id: 0 }), + value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: kabel_irj, variable_id: 0 }), + }, + TableValue { + key: VMMemory::String(VMMemoryString { value: String::from("zár"), variable_id: 0 }), + value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: kabel_zar, variable_id: 0 }), + }, + TableValue { + key: VMMemory::String(VMMemoryString { value: String::from("id"), variable_id: 0 }), + value: VMMemory::Number(VMMemoryNumber { value: (machine.storage.len()-1) as f64, variable_id: 0 }), + } + ]; + return VMMemory::Table(VMMemoryTable { values: ret_table, variable_id: 0 }); +} fn kabel_halgass(machine: &mut Machine, op: &DecompiledOperation, args: Vec) -> VMMemory { arg_expect(&args, 0, "string", machine, op); arg_expect(&args, 1, "number", machine, op); @@ -1161,6 +1195,10 @@ pub fn generate() -> HashMap { TableValue { key: VMMemory::String(VMMemoryString { value: String::from("halgass"), variable_id: 0 }), value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: kabel_halgass, variable_id: 0 }), + }, + TableValue { + key: VMMemory::String(VMMemoryString { value: String::from("kapcsolódj"), variable_id: 0 }), + value: VMMemory::NativeFunction(VMMemoryNativeFunction { func: kabel_kapcsolodj, variable_id: 0 }), } ]; mem.insert(String::from("kábel"), VMMemory::Table(VMMemoryTable { values: kabel, variable_id: 0 })); diff --git a/src/main.rs b/src/main.rs index 3de6c12..291e975 100644 --- a/src/main.rs +++ b/src/main.rs @@ -10,7 +10,7 @@ mod virtualmachine; mod errors; mod decompiler; -const CLIVER: [u8; 3] = [1,0,0]; +const CLIVER: [u8; 3] = [1,0,1]; #[derive(Debug, Clone)] struct Context { diff --git a/test.asl b/test.asl index 5b5aa9a..c56098e 100644 --- a/test.asl +++ b/test.asl @@ -1,11 +1,8 @@ -lőcsve test() { - lőcsve toast() { - ugass(2) - } - toast() - ugass(1) -} -gethelj k = krumpli.létrehoz(test) -ugass(krumpli.státusz(k)) -krumpli.folytat(k) -ugass(krumpli.státusz(k)) \ No newline at end of file +gethelj con = kábel.kapcsolódj(szaft"example.com:80"szaft) +con.írj(con, szaft"GET / HTTP/1.1 +User-Agent: Astro Lang +Host: example.com + +"szaft) +ugass(con.olvass(con, 5120)) +con.zár(con) \ No newline at end of file