[ / / / / / / / / / / / / / ] [ dir / hikki / htg / hwndu / lovelive / newbrit / russian / strek / zoo ][Options][ watchlist ]

/tech/ - Technology

You can now write text to your AI-generated image at https://aiproto.com It is currently free to use for Proto members.
Name
Email
Subject
Comment *
File
Select/drop/paste files here
* = required field[▶ Show post options & limits]
Confused? See the FAQ.
Expand all images

File (hide): a78d702ce36a0e6⋯.png (25.62 KB, 383x327, 383:327, nlang.png) (h) (u)

[–]

 No.797373>>797382 >>797387 >>797548 >>797564 >>797567 >>805309 [Watch Thread][Show All Posts]

So, I've had these ideas brewing for a while, and thought I'd share it with you all. This is a programming language that I thought of. Please give me your thoughts. Constructive criticism is much appreciated.

1/3

[[$]] example. ;; define namespace.

;;->
multiline comments.
<-;;

;;-> Imports
$<[[package]]. imports full paths
$<[[package]]::*. imports all exported functions into the current namespace
$<[[package]]::[func obj]. imports specific items
<-;;

;; Variable declarations and definitions
var: i32.
var2: u32 = 5.
var3 := 5. ;; The compiler can auto-fill the type if it can be statically
;; detected.

;;-> Number types
Unsigned: u8/u16/u32/u64
Signed: i8/i16/i32/i64
Floating point: float/double
<-;;
123_456_789,555. ;; supports underscores like perl
0b011000101.
0o755.
0xDEADBEEF.
2.147e9.
'c'. ;; u8

;; Casts are done like:
u8 -15.
;; or:
u8{-15}.

"hello world". ;; u8[11] <- The size is the first item in C code, see below.

;;-> Arrays
Arrays are special, in which they are converted to C code where
the first item of the array is the array's size. While this adds some
overhead, this makes the C code completely memory safe by
checking the array length for anything involving array bounds.
The length is read-only in Nlang code.
<-;;
[1 2 3]. ;; u32[3]
["Hello" "World" "!\n"]. ;; u8[][3]

;;-> Tuples
Tuples are a special kind of array, in which they hold 2 arrays, one
for type data and one for the actual items. They have more
overhead in exchange for the ability to store different items
in the same data structure. Multiple function parameters use this,
which is then optimized into multiple arguments in the transpiler.
Thus it is possible to construct the arguments of a function separately.
<-;;
{1 2 "Fizz" 4 "Buzz"}. ;; tuple{i32 i32 u8[4] i32 u8[4]}

;;-> Structs
Structs do not have private or protected members. Inheritance is done with:
#(name: parent -> ...)
You can have multiple members of the same type by making an array of names
equate to a type. This is transparently converted in the transpiler.
<-;;
#(my_struct ->
[member member2]: i32.
name: u8[].
). ;; #{i32 i32 u8}

;;-> The registry
The global namespace is called the "registry". All exported functions must
be exported to the registry to be used by other packages.
If they are not exported to the registry, they will be package-private.
if an object is named, you can directly import it into the registry like $<your_object.
otherwise, you can export it into a member of the registry: $::name<object.
<-;;

;;-> If/else
The only if/else is ternary. :^)
cond ? (true body).
cond ? (true body) : (false body).
cond ? (if body) : cond2 ? (elseif body) : (else body).
<-;;

;;-> Loops
There are no loops by default, a la Haskell.
array::map is converted into for (int i = 1; i < array[0]-1; i++) in C.
While loops is defined in the standard library as
[[iterators]]::while{cond: %->bool func: %->}. (%-> is function taking and
returning nothing, and %->bool is function taking nothing and returning a bool.)
<-;;

 No.797374

2/3

;;-> Functions
Synopsis: %([name] {arg: type arg: type ...} return type -> function body).
Name is optional, but required when directly exporting to registry.
You can omit {args} to have no args.
arg: type = default_val or arg := default_val
Use arg: type... for varargs. The resulting argument will be a type[arglen].
Using arg... will make arg a tuple with the remaining args.
Omit return type for void.

Call a function with no arguments: func!.
Call a function with 1 argument: func arg.
Call a function with 2+ arguments: func {arg arg arg}.
The latter is still one argument (a tuple) which is implicitly converted to
multiple args. You can omit the space between the function name and the arg if
the arg doesn't start with an alphanumeric character, i.e.
printf"Hello World\n". or func{arg arg arg} but not square5.
<-;;
$::square < %({num: u32} u32 ->
;;-> Multiline string on the first line is docstring. <-;;

;; Return values are the result of the last statement.
num * num.
).

;; This could also be written as:
%({num: u32} u32 -> num*num).
;; The dot is not required on oneliners.

;;->
Object Oriented Programming
<-;;
$<[[stdlib]]::*.

;; generic structs
$::vector(T)<#(
items: T[].
len: 0.
).

;;-> Methods
Methods are just functions which take the struct as their
first argument. They are defined as properties of the struct.
The first argument must be prefixed with & and must have no
type. If this is omitted, the method is static.
The generic identifier can be omitted if the type is not used.

There are two ways to call methods:
obj::method arg and method obj arg.
<-;;

;;->
By default, every struct has a `new` method which uses
malloc to initialize it on the heap (unless disabled by the user).
You can override it to do special initialization. You can call
the overridden function with super.
<-;;

;;-> Exceptions
Exceptions are thrown with
Exception::throw"message" or throw Exception "message".
Struct Exception is in the stdlib package [[exceptions]].
Exceptions can be caught with
Exception::catch{try: %-> catch: %{Exception}->}.

Example:

$<[[exceptions]]::Exception.
$<[[stdio]]::printf.

bad_function<%(-> Exception::throw"Something went wong").

$::main<%({argc: i32 argv: u8[][]} i32 ->
Exception::catch {%(-> bad_function!)
%({err: Exception} -> $::printf err::message)}.
0.
).
<-;;

;;-> You can omit $:: to refer to symbols in the same module, except when
exporting. i.e. $::vector -> or vector -> <-;;
$::vector(T)::new<%({items: T...} vector(T) ->
;;-> Creates a new vector with items. <-;;

;;-> you can use special syntax sugar for creating new
variables from the result of staticmethods:
method var: obj. <-;;
super this: vector.

this::items::free!.
this::items = items.
this::len = items::len.
this.
).

;; Function overloading
$::vector(T)::new<%(vector(T) -> super!).

;; This is an example of a non-static method.
$::vector(T)::push<%({&this item: T} ->
this::items = $::realloc {this::items (this::len+1)*T::size}.
this::items[this::len] = item.
this::len++.
).

;; Another example of a non-static method.
$::vector(T)::push<%({&this} T ->
;; Explicit return.
this::len == 0? return nil.
this::len--.

item := this::items[this::len].
this::items = $::realloc {this::items this::len*(T::size)}.

item.
).


 No.797375

3/3


;;-> Operator overloading
There are 4 kinds of operator overloading in Nlang:
- Prefix: $::`op`struct<%({&this} ... -> ...).
- Unary prefix: $::`op`struct<%({&this that: ...} ... -> ...).
- Unary suffix: $::struct`op`<%({&this that: ...} ... -> ...).
- Suffix: $::struct`op`<%({&this} ... -> ...).
You can add any kind of operator so long as it isn't alphanumeric.
Operators must be used directly adjacent to the identifier.
<-;;

;; Assume that vector::copy is defined.
$::vector(T)`+`<%({&this that: T} vector(T) ->
vec := copy this!.
push vec that.
vec.
).

;; Operators for pushing, popping, shifting and unshifting.
$::`<`vector(T)<%({&this} T -> unshift this!).
$::`>`vector(T)<%({&this item: T} -> shift this item).
$::vector(T)`>`<%({&this} T -> pop this!).
$::vector(T)`<`<%({&this item: T} -> push this item).

;;-> Usage of these operators

<vec Unshifts the first item and returns it.
>vec item Shifts item in.
vec> Pops the last item.
vec< item Pushes item.

Because the operator must be directly adjacent to the object, this does not
cause conflicts with other objects' operators.
i.e. obj$ ^obj.
The default operators [+ - * / %] are special; if they aren't adjacent or they
are not overloaded on either of the objects they perform they try to do
arithmetic operations.
<-;;

;; Some code examples

;; FizzBuzz
$::fizzbuzz<%({n: i32} ->
;;-> Prints FizzBuzz until n. <-;;

;;->
{1..n} is a range. It's right hand exclusive by default. If evaluated,
it becomes an array. You can define step with {start..end..step}.
When range::map is used, this is optimized into a for loop in C code.
<-;;

{1..n}::map %({i: i32} ->
i%15 == 0?
$::printf"FizzBuzz\n"
:i%5 == 0?
$::printf"Buzz\n"
:i%3 == 0?
$::printf"Fizz\n"
: $::printf{"%d\n" i}.
).
).

;;-> Generators
When a function uses the `yield` keyword to return a value, it becomes a
generator. Generators stop execution at the point they yield a value, and
continue when called again. A generator's variables are static.
<-;;

$<[[iterators]]::while.

;; Fibonacci
$::fibonacci<%(i32 ->
a := 0.
b := 1.
$::while %(bool -> true) %(->
yield a.
a = b.
b = a + b.
).
a.
).


 No.797378>>797385

Was C++ not ugly enough for you, OP?


 No.797380

cool logo dude!!!


 No.797381>>797385

yeah, since it's only a concept so far, it doesn't really do anything new that justifies the cumbersome syntax or not having while loops


 No.797382>>797383 >>797385

>>797373 (OP)

My suggestion is that you write the compiler in rust. Also needs more semicolons.


 No.797383

>>797382

shut up, Walken


 No.797385>>797389

>>797378

>>797381

I don't think the syntax is that bad, honestly. It allows for more one liners and more natural feeling code with `verb noun object` syntax sugar, i.e. `push vec item` or `unshift vec!`.

>>797382

I'm writing a bootstrap transpiler in Python, which I will use to transpile the basic functionality of the transpiler and then work my way up. I'll release 1.0 when it can transpile all language features.


 No.797387

>>797373 (OP)

Looks like shit tbqh. Even Rust looks more readable.


 No.797389

>>797385

>more one liners

>implying it's something valuable


 No.797390>>797393 >>797394

Does it actually do anything or is it just an alternative syntax with unnecessary symbols that could be 1:1 translated to C by a perl program?


 No.797393>>797394 >>797395

>>797390

It does memory safety for arrays by storing the length of an array as its first item, and then doing bound checking with every operation that involves array bounds. It also corrects some of C++'s mistakes with object orientation like "methods are not functions with this as the first argument", and adds new operator overloading methods. There's also tuples, which are like arrays but also store type info to store different types of data in the same datastructure.


 No.797394

>>797393

>>797390

Addition: This will be a transpiled language to C, which is then fed into gcc or clang.


 No.797395>>797399

>>797393

Why not just do that but following some syntax standard people are used to?


 No.797399>>797412

>>797395

Then how can I be a special snowflake? :^)

Besides, C's syntax is mostly broken anyways.


 No.797412>>797428

>>797399

>Besides, C's syntax is mostly broken anyways.

Then tell us how your syntax fixes C's, because it's not exactly self-evident.


 No.797428

>>797412

I never said it did. It's a different syntax. It may have its own shortcomings but I like it more.


 No.797439

lol at your "memory safety" that only amounts to bounds checking


 No.797548>>797564

File (hide): 49853b2fd21055b⋯.png (58.67 KB, 383x327, 383:327, nlang.png) (h) (u)


 No.797558

File (hide): 75a589ac3f503b5⋯.png (11.53 KB, 703x279, 703:279, n lang a.PNG) (h) (u)

Syntax is quite bad.


 No.797564

File (hide): 6c51587b676198b⋯.png (59.98 KB, 383x327, 383:327, n.png) (h) (u)


 No.797565

Close examination of OP's language leads me to believe that he is a doctor who treats repetitive strain injuries of the hands and wrists, and he's trying to drum up business.


 No.797567>>797569

>>797373 (OP)

is there a problem that this is a solution to?


 No.797569

>>797567

The CISC esolang field has stagnated since INTERCAL


 No.797579

Why would I not just use Nim or Rust? Both of those languages have everything that N-lang offers, and more. Also why would you end the line with a decimal? Use a semicolon like every other language, and use // or # for comments. This just seems like a generic C-like language with funny syntax.


 No.797581

Introducing F-Lang 1/3

package example  \ define a namespace

0 [IF] a multiline comment. We won't be using these because it's better to
comment out multiple lines
[THEN]

\ Imports
other-package +order \ adds even private words to search order
\ normally we don't do fancy shit with packages. We load libraries and
\ packages are mostly used to hide package-internal words. You can open
\ a package, modify it with access to its internal words, and then close
\ it though:
package yet-another-package \ where the package already exists

public

: .secret ( -- )
package-secrets 100 dump ;

end-package

\ Variable declarations and definitions
variable v1
5 value v2
5.2e fvalue f1


\ Number types (with a 64-bit environment)
-5 . \ signed output: 5
-5 u. \ unsigned output: 18446744073709551611
-5 -1 d. \ signed 128-bit output: -5
-5 -1 ud. \ unsigned 128-bit output: 340282366920938463463374607431768211451
-5e f. \ floating point
\ specific kinds floating point only matter when working with memory
-5e GL-address sf!
-5e normal-float f!
-5e who-even-uses-these df!

123.456.789 \ any dots in non-float indicate a 128-bit number
\ some implementations are even more flexible
#123 . \ always decimal, decimal output: 123
$123 . \ always hex, decimal output: 291
%101 . \ always binary, decimal output: 5
'c' . \ ASCII value for c, decimal output: 99

\ You can convert (not cast) between some types
5e f>d d>s \ float to double-sized integer to single-sized (64-bit)
\ some other cast-like options are possible when writing to memory

\ Arrays
\ -- Arrays are not special. They are just contiguous spans of memory.
\ Although cache effects and the speeds of different ways of accessing memory
\ do mean that arrays are better types than you're perhaps aware.
\ fucking lisp fags.

create numbers
1 , 2 , 3 ,
here numbers cell / constant #numbers \ ex. calculating membership
numbers ? \ decimal output: 1
numbers 1 cells + ? \ decimal output: 2

\ Tuples
\ Because F-lang gives you precise and explicit control over memory, you
\ can do anything you want with it, including this stupid idea about
\ heterogeneously-typed arrays, which is a stupid thing to have.

\ Structs
\ Do not have 'inheritance', although you can nest them in obvious ways.

0
1 cells +field cdr
constant list

list
1 cells +field x
1 cells +field y
constant coordinate

\ of course you could just use a generic cdr/car list and have car
\ contain the address to a two-cell structure containing only the
\ coordinates. You could do that if you were gay.

\ The search order
\ When a name is encountered, that name is looked up in each wordlist
\ in the search order, obviously "in order", and then if found a
\ function is performed according to that wordlist's definition of the
\ word. This is such a simpler and yet more powerful concept than some
\ kinda 'registry' that I feel bad for anyone not having it.

\ If/else
: some-word ( -- )
cond if (true-body) then (the-rest-of-the-word)
cond if (true-body) else (false-body) then (the-rest-of-the-word) ;

\ Loops
\ There are no loops by default, a la Haskell.
\ But in the standard library a loop is defined anyway, you fruitcake.
\ And the standard library is loaded by default.
\ What do you think that means about the default for the language?
: some-word ( -- )
begin (test) while (while-case) repeat
begin (while-case) (negative-test) until
begin (infinite-loop) again
\ this is dead code on account of the infinite loop
\ but anyway
10 0 do (-this-ten-times) loop
10 0 do i . loop \ outputs: 0 1 2 3 4 5 6 7 8 9

begin (test)
while (another-test)
while (while-case)
repeat then \ as many THENs as additional WHILEs
\ that looks crazy? it's just mind-expanding a la Haskell


 No.797582

2/3

\ Functions
\ Synopsis: : name ( stack comment ) words it does ; modifiers
\ name is required. use :NONAME to create an anonymous word

\ Call a function with no arguments: FUNC
\ Call a function with 1 argument: FUNC
\ Call a function with 2+ arguments: FUNC

\ This is advanced shit. You need a computer science degree to
\ understand the subtle differences between the previous examples.

: square ( n -- n' )
dup * ;

\ This could also be written as:
: square ( n -- n' ) dup * ;

\ Technically ( whatever ) is an inline comment but technically you
\ can rape people if you want and it's purely a technicality that
\ you'll be caught and thrown in prison. What I'm saying is include
\ the comment or you'll be thrown in prison.

\ Object Oriented Programming
class vector
variable items
variable length
: show ( -- ) \ this is a method
." v[ " length @ 0 ?do \ so it has direct access to attributes
items @ i cells + ?
loop ." ]" ;
end-class

\ Exceptions
42 ( that's an exception code ) throw

' some-word-what-may-throw catch

\ Example:
variable handler
: fuck-you-exception true abort" something went wrong lol" ;
: bad-word ( -- ) ['] fuck-you-exception handler ! 42 throw ;
: main ( -- )
['] bad-word catch dup if
\ oh no BAD-WORD threw an exception!
case
42 of handler @ execute endof
dup throw \ we don't know about this one, rethrow it
endcase
else
\ nothing happened yay
then ;

\ You can refer to words by just writing the name of the word
\ if you want its execution token instead of actually executing
\ it, you can write ' WORD , or ['] WORD within a definition.

\ How's that for syntax sugar?

vector builds v
10 cells buffer: v-items
v-items v items !
:noname ." bugger" ; v items @ !
:noname ." me" ; v items @ 1 cells + !
2 v length !

\ v is now a vector that contains a 10-cell buffer, which contains
\ the execution token of a word that says 'bugger', and another
\ that says 'me'. v's defined length is 2.
\ this VECTOR word is a class that's defined above as an example.

\ "Function overloading"
vector subclass shy-vector
: show ( -- ) ." noooo I don't wanna" ;
end-class

v show \ example output: v[ 270886848 270886912 ]
v addr USING shy-vector show \ output: nooo I don't wanna


 No.797583>>797584

3/3

\ Some code examples
: fizzbuzz ( -- ) \ it's an exercise defined to print until 100
101 1 do cr
i 3 mod 0= i 5 mod 0= 2dup and
if ." FizzBuzz" 2drop else
if ." Fizz" drop else
if ." Buzz" else
i .
then then then
loop ;

\ Using 'continuations'
: call ( cont -- ) >r ;
: forever ( -- ) begin r@ call again ;
: omg ( -- ) forever 5 . ;
omg \ output: 5 5 5 5 5 5 5 5 5 5 5 5 ...(and so on)


 No.797584

>>797583

ah fug I reversed Fizz/Buzz with the original's retarded in-order-of-factors implementation. Now I'll never get a job in programming.


 No.797606>>797617

File (hide): c7b67af5d78497e⋯.jpg (67.52 KB, 640x656, 40:41, hol up.jpg) (h) (u)

Hmm, I don't like how radically different and complex the syntax is (though the fact that you encapsulated all your design documentation in a code tag doesn't help with readability either), it's like you're trying to remake Perl lol, but I do see some ideas that I like, like the 'registry'... Might incorporate that into my own programming language (I do find it funny how we both came up with strikingly similar ideas for constructors though).

If I were you I'd give functions without arguments a different name like 'procedure'. The 'yield' keyword's behavior is interesting but I think it would be hard to implement.


 No.797617>>797621

>>797606

>Hmm, I don't like how radically different and complex the syntax is (though the fact that you encapsulated all your design documentation in a code tag doesn't help with readability either), it's like you're trying to remake Perl lol,

It's a post-modern parody of Rust. It has some stuff from Perl too.

>but I do see some ideas that I like, like the 'registry'...

It's going to be this big philosophy around it.

>If I were you I'd give functions without arguments a different name like 'procedure'.

There isn't really a benefit to it, in fact func! is just $::Function`!`, it's just a postfix operator which does func {}.

>The 'yield' keyword's behavior is interesting but I think it would be hard to implement.

Languages like JavaScript and Python have it already, with the same semantics.


 No.797621>>797629

>>797617

>There isn't really a benefit to it, in fact func! is just $::Function`!`, it's just a postfix operator which does func {}.

I meant in terms of documentation, I think it would be a good distinction to make for beginners learning your language.

>Languages like JavaScript and Python have it already, with the same semantics.

I've been doing python for 4 years now and I never knew that, how funny.


 No.797629>>797631

>>797621

>I meant in terms of documentation, I think it would be a good distinction to make for beginners learning your language.

Okay then. There isn't even an official spec yet, I'm just trying to squeeze my ideas through the tiny hole of the reality filter.

That came out edgier than I thought

>I've been doing python for 4 years now and I never knew that, how funny.

I think it's a Python 3 addition. I have personally never used generators, but it's an interesting feature.


 No.797631

>>797629

btw update, I finished the lexer and am currently working on the type system and the parser. I do not have very much time nowadays so I can't do much with it yet. I'll put it on gitgud.io after I get Hello World to transpile.


 No.798656>>799429 >>799669

>ITT: "syntax is what makes a language good and this syntax is gay ecks dee"

the syntax makes me want to cut myself but what is this language used for OP? what's your goal with it?


 No.799429>>799669

>>798656

dont think OP has thought about more than syntax because op is a nigger


 No.799454>>799669

Why should I use this over Myrddin?


 No.799515>>799540 >>799669

Shit syntax, therefore write-only, therefore relegated to esolang status at best, meme status at worst.

Seriously, what's wrong with C-style syntax, and why do all memelangs try so hard to avoid it?


 No.799540>>799669

>>799515

>write-only

what does that mean?


 No.799669>>799676

>>798656

It's supposed to be a general-purpose language, I guess. I haven't really thought about it. >>799429 is right. :^)

>>799454

>Myrddin

literally who

>>799515

syntax is subjective :^)

Let it be an esolang. It's just something I am trying to implement as a programming exercise/hobby. I plan to implement an operating system with it once it matures enough, to become a Parkourdude91 tier ebin trolll xD.

>>799540

He's suggesting that the language is hard to read and that once you write it, nobody else can read it. He does have a point.


 No.799676>>799677

>>799669

>He's suggesting that the language is hard to read and that once you write it, nobody else can read it.

so it's a pleb filter. im ok with this


 No.799677

>>799676

well technically it's agreed that perl is write-only too, and it's a good language, so :^)

i know, correlation is not causation, let me have some ego you autistic fucks


 No.803069>>803072

After long last, an update.

First off, I created a repo to push to for this. Currently only a (half-baked) parser is available, but I'll work on it in my free time to create the rest of the transpiler.

https://gitgud.io/m712/nlang/

Also, the parser is semi-working. You can feed it statements and some of the language gets processed fine. Currently identifiers, strings, numbers, floats, chars, arrays, most types, pointer types, array types, identifiers, function calls and `method obj arg` syntax sugar works. I'm adding more of the syntax as time goes on.

>>> from src.parser import Parser, sparser
>>> sparser.type('u8[4]')
...
<ArrayTypeASTExpr: u8[4]>
>>> sparser.expr('$::printf"Hello World!".')
...
<CallASTExpr: $::printf {[H e l l o W o r l d !]: u8[12]}>
>>> sparser.expr('1*3+3/7-0')
...
<BinaryASTExpr: (((1: i32) * (3: i32)) + ((3: i32) / (7: i32))) - (0: i32)>

The ... is there as placeholder for the lines the lexer spits out for debugging.


 No.803072

>>803069

>(((formatting))) gets inside code tags

good job cuckmonkey


 No.805172>>805302 >>805321

Dear OP. (ur a phaggot)

These days every good programmer can design a programming language and some companies actually do it for some reason. (projects too)

As long as you don't aim to make a whole compiler yourself you can just rely on compiling your lang to something like barely-readable optimized JavaScript, C, C-- (yes, it's a thing) or to just about any other language depending on runtime you're going to use it in.

Either way, don't expect anyone to adopt your newly designed programming language if you don't give them any reason to nor expect it to land you any job.


 No.805302>>805321

>>805172

OP is having fun making a language. You're the fag here.


 No.805309>>805312

>>797373 (OP)

>Arrays are special, in which they are converted to C code where the first item of the array is the array's size.

>While this adds some overhead, this makes the C code completely memory safe by checking the array length for anything involving array bounds.

>The length is read-only in Nlang code.

Why the fuck would you make the first element in an array the length?

Aren't all elements in an array supposed to have the same length? Or are you confusing arrays with lists?

Why wouldn't you make arrays as structures in C with a length member and a C-array member?


 No.805312>>805460

>>805309

I should be clear with my second sentence. What if what you have is an array of chars that is longer than 256?

Would your array have an int as the first element and then a bunch of chars? That's stupid.


 No.805321

File (hide): cbfb5f8d8d050f3⋯.jpg (6.65 MB, 9001x9001, 1:1, giant bunny.jpg) (h) (u)

>>805302

How new are you OP is always a faggot regardless of circumstance. In this case you're confused because >>805172 is also a faggot.


 No.805460

>>805312

;; char small_str[5] = {4, 't', 'e', 's', 't'};
small_str := "test".
;; char long_str[288] = {255, 36, ..., 'e', 'r', 'e'};
long_str := "imagine a long string here".

;;-> In the transpiler
new items: $::vector(u8).
len := str::len.
$::while %(i32 -> len > u8::max) %(->
push items u8::max.
len = len - u8::max.
).
items::push len.
str::map %({c: u8} -> push items c).

etc. etc. <-;;


 No.807583>>807643

M8, I'm not sure you'll get a lot of people to use this. I used to write in assemblers, qbasic, gwbasic, Pascal and derivatives, C and derivatives and so on, and so forth. I gave up after the first part and just skimmed the rest for relevant parts.

The only thing I can advise from what I saw in that snippet from that other thread is dropping this last statement as return value madness. Use an explicit return keyword. Because otherwise just one even marginally hasty edit turns

$::meme<%({argc: u32 argv: i32[2]} i32 ->
sprudo: i32.
sprade: i32.
sprudo = argv[0] + argv[1].
argv[0]++.
argv[1]--.
sprade = argv[0] - argv[1].
sprudo * sprade.
).

into complete fucking nightmare

$::meme<%({argc: u32 argv: i32[2]} i32 ->
sprudo: i32.
sprade: i32.
sprudo = argv[0] + argv[1].
argv[0]++.
argv[1]--.
sprudo * sprade.
).

Or even

$::meme<%({argc: u32 argv: i32[2]} i32 ->
sprudo: i32.
sprade: i32.
sprudo = argv[0] + argv[1].
argv[0]++.
argv[1]--.
sprade = argv[0] - argv[1].
).

or just

$::meme<%({argc: u32 argv: i32[2]} i32 ->
sprudo: i32.
sprade: i32.
sprudo = argv[0] + argv[1].
argv[0]++.
argv[1]--.
).

>b-but I'll check for every possible pitfall!

>it'll be memory-safe like rust

It seems like you've at least studied writing of compilers as part of your uni course, maybe even wrote something simple. My advise would be to stop reinventing the wheel for the billionth fucking time.


 No.807643

>>807583

You should always know what you're returning though, TBF. If you don't want to return anything, just omit the i32 before -> and the function will be void, and the return wrapper won't happen. And again, I'm doing this as a programming exercise/for fun, I don't expect to get a job with it, I don't expect people to like it.

Also, I've made many commits to the git, I can get hello world to transpile 90% now.




[Return][Go to top][Catalog][Screencap][Nerve Center][Cancer][Update] ( Scroll to new posts) ( Auto) 5
52 replies | 6 images | Page ???
[Post a Reply]
[ / / / / / / / / / / / / / ] [ dir / hikki / htg / hwndu / lovelive / newbrit / russian / strek / zoo ][ watchlist ]